#include "tm_tmd_utils.h"

bool CompareVertex(Vertex& v1, Vertex& v2)
{
	int diff = 0;

	if (!(v1.Position[0] == v2.Position[0]
	&& v1.Position[1] == v2.Position[1]
	&& v1.Position[2] == v2.Position[2]))
			diff++;
	
	if (!(v1.Normal[0] == v2.Normal[0]
	&& v1.Normal[1] == v2.Normal[1]
	&& v1.Normal[2] == v2.Normal[2]))
			diff++;

	if (!(v1.TexCoord[0] == v2.TexCoord[0]
	&& v1.TexCoord[1] == v2.TexCoord[1]))
			diff++;

	return (diff == 0);
}

int AddDropDuplicates(Vertex v1, std::vector<Vertex>& target)
{
	//if this vert is already in the array get its index
	if (!target.empty())
	for (int i=0; i<target.size(); ++i)
		if (CompareVertex(target[i], v1))
			return i;

	//otherwise add it and return its index
	target.push_back(v1);
	return (int)target.size() - 1;
}